<html>
<head><meta charset="utf-8"><title>Getting a compile-time list of names from a crate · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html">Getting a compile-time list of names from a crate</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="230770541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230770541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230770541">(Mar 17 2021 at 21:32)</a>:</h4>
<p>Would it be possible for Rust to generate a list of names provided by a crate, and provide such a list as a compile-time constant (either as a const <code>&amp;[&amp;'static str]</code> that could be used by a proc macro or build script, or perhaps as a list usable by a macro)?</p>



<a name="230770604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230770604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230770604">(Mar 17 2021 at 21:32)</a>:</h4>
<p>For instance, "give me the list of all of libc's <code>pub</code> names"?</p>



<a name="230770656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230770656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230770656">(Mar 17 2021 at 21:33)</a>:</h4>
<p>From a crate that depends on <code>libc</code>, I mean.</p>



<a name="230770720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230770720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230770720">(Mar 17 2021 at 21:33)</a>:</h4>
<p>Is that something that'd be 1) feasible for the compiler to do, and 2) a vaguely reasonable thing to ask for?</p>



<a name="230770824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230770824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230770824">(Mar 17 2021 at 21:34)</a>:</h4>
<p>I'm thinking about it for the purposes of writing certain kinds of comprehensive tests. For instance, "give me all the <code>SIGFOO</code> signals defined in <code>libc</code> for this target".</p>



<a name="230770873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230770873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230770873">(Mar 17 2021 at 21:34)</a>:</h4>
<p>It'd be nice to be able to get that information from the compiler, rather than having to create and export such a list from the crate in question.</p>



<a name="230772122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230772122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230772122">(Mar 17 2021 at 21:44)</a>:</h4>
<p>a macro that extracts the list of symbols from the rlib of a dependency seems no more inherently unreasonable than <code>include_str!</code> is</p>



<a name="230775480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230775480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230775480">(Mar 17 2021 at 22:04)</a>:</h4>
<p><code>include_symbols!(some_direct_dependency_crate_name)</code> ?</p>



<a name="230793994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230793994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230793994">(Mar 18 2021 at 00:59)</a>:</h4>
<p>My question would be, what form do the names take, and also what names would be exported? Just functions and statics? Functions, statics, and types? Are generics included?</p>



<a name="230806854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230806854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230806854">(Mar 18 2021 at 02:56)</a>:</h4>
<p>that almost sounds like a reflection API</p>



<a name="230807268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230807268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230807268">(Mar 18 2021 at 03:02)</a>:</h4>
<p>Very <em>very</em> carefully not suggesting reflection here, because this is not a runtime feature, it's a compile-time feature.</p>



<a name="230807278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230807278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230807278">(Mar 18 2021 at 03:03)</a>:</h4>
<p>And: pub functions, pub constants, pub types, anything you could name via <code>cratename::NAME</code>.</p>



<a name="230808930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230808930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230808930">(Mar 18 2021 at 03:30)</a>:</h4>
<p>Could part of this be the conversation about a json output from rustdoc?  It seems like just a list of strings isn't enough to do something particularly interesting.</p>



<a name="230813112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230813112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230813112">(Mar 18 2021 at 04:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate/near/230807268">said</a>:</p>
<blockquote>
<p>Very <em>very</em> carefully not suggesting reflection here, because this is not a runtime feature, it's a compile-time feature.</p>
</blockquote>
<p>I was thinking more like the <a href="https://www.youtube.com/watch?v=ARxj3dfF_h0">C++ nemesis</a> library, which is static reflection. Probably to do anything really fancy though it would be better to do this in a <a href="http://build.rs">build.rs</a> script</p>
<div class="youtube-video message_inline_image"><a data-id="ARxj3dfF_h0" href="https://www.youtube.com/watch?v=ARxj3dfF_h0"><img src="https://i.ytimg.com/vi/ARxj3dfF_h0/default.jpg"></a></div>



<a name="230818490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20a%20compile-time%20list%20of%20names%20from%20a%20crate/near/230818490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20a.20compile-time.20list.20of.20names.20from.20a.20crate.html#230818490">(Mar 18 2021 at 06:21)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> It's enough for various kinds of tests, including checking symbol availability and writing exhaustive tests checking all symbols with certain name patterns.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>